package com.blame.springblog.controller;


import com.blame.springblog.pojo.request.AddBlogRequest;
import com.blame.springblog.pojo.request.UpdateBlogRequest;
import com.blame.springblog.pojo.response.BlogInfoResponse;
import com.blame.springblog.service.BlogInfoService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/blog")
public class BlogInfoController {

    @Resource(name = "blogInfoServiceImpl")
    private BlogInfoService blogInfoService;

    @RequestMapping("/getList")
    public List<BlogInfoResponse> getList(){
        return blogInfoService.getList();
    }

    @RequestMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull Integer blogId){
        log.info("blogId:{}",blogId);
        return blogInfoService.getBlogDetail(blogId);
    }

    @RequestMapping("addBlog")
    public Boolean addBlog(@RequestBody @Validated AddBlogRequest addBlogRequest){
        return blogInfoService.addBlog(addBlogRequest);
    }

    @RequestMapping("/update")
    public Boolean updateBlog(@RequestBody @Validated UpdateBlogRequest updateBlogRequest){
        return blogInfoService.updateBlog(updateBlogRequest);
    }

    @RequestMapping("/delete")
    public Boolean deleteBlog(Integer blogId){
        return blogInfoService.deleteBlog(blogId);

    }
}

